package cn.com.infohold.smartcity.parent;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import common.base.BaseFragment;
import common.utils.ViewUtils;
import library.permission.PermissionsManager;


/**
 * Created by Mr.Fan on 2016-4-7.
 */
public abstract class ParentFragment extends BaseFragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//        View view=super.onCreateView(inflater, container, savedInstanceState);
        Object obj = inflateView();
        View view = null;
        if (obj instanceof Integer)
            view = inflater.inflate(Integer.parseInt(obj.toString()), container, false);
        else if (obj instanceof View)
            view = (View) obj;
        else
            throw new RuntimeException("unexpected view inflate :" + obj);
        ViewUtils.inject(this, view);
        initView(view);
        return view;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    protected abstract Object inflateView();

    protected abstract void initView(View anchor);


    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        PermissionsManager.getInstance().notifyPermissionsChange(permissions, grantResults);
    }


    public boolean onBackPressed() {
        return false;
    }
}
